import request from "@/utils/request.ts";
import {ApiResponse} from "@/types/request.ts";
import {WeatherAll, WeatherCapitalForecast, WeatherHours,} from "@/types/weather.ts";
import {Page, RealData} from "@/types/common";

/**
 * 天气相关接口
 */
export default {
    /**
     * 通过ip获取本地天气信息
     */
    fetchLocalWeather: async () : Promise<ApiResponse<WeatherAll>> => {
        return request({
            url: '/weather/',
            method: 'get'
        })
    },
    /**
     * 通过adcode获取本地天气信息
     * @param adcode 行政区划代码
     */
    fetchLocalWeatherByAdcode: async (adcode: string) : Promise<ApiResponse<WeatherAll>> => {
        return request({
            url: `/weather/adcode/${adcode}`,
            method: 'get'
        })
    },
    /**
     * 分页获取省会城市未来天气信息
     */
    fetchCapitalCitiesForecastsByPage: async (page?: number, size?: number) : Promise<ApiResponse<Page<WeatherCapitalForecast>>> => {
        return request({
            url: '/weather/forecasts',
            method: 'get',
            params: {
                page,
                size
            }
        })
    },
    /**
     * 获取省会城市实况天气信息
     */
    fetchCapitalCitiesHoursWeather: async () : Promise<ApiResponse<RealData<WeatherHours[]>>> => {
        return request({
            url: '/weather/capital',
            method: 'get'
        })
    },
}